<?php 
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

/* 后台设置 */
function themeConfig($form) {
    //站点logo地址
    $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点LOGO地址'), _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO'));
    $form->addInput($logoUrl->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符')));

    //首页博客的介绍
    $blogMesg = new Typecho_Widget_Helper_Form_Element_Text('blogMesg', NULL, NULL, _t('首页博客的介绍'), _t('在这里填入首页博客的介绍, 以在网站首页显示'));
    $form->addInput($blogMesg->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符')));

    //侧边栏
    $sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock', 
    array(
    'ShowBlogmiao' => _t('站点描述'),
    'ShowCategory' => _t('文章分类'),
    'ShowRecentPosts' => _t('最新文章'),
    'ShowRecentComments' => _t('最新评论'),
    'ShowAdmin' => _t('系统设置')),
    array('ShowBlogmiao', 'ShowCategory', 'ShowRecentPosts', 'ShowAdmin'), _t('侧边栏显示'));    
    $form->addInput($sidebarBlock->multiMode());


    //统计代码
    $GoogleAnalytics = new Typecho_Widget_Helper_Form_Element_Textarea('GoogleAnalytics', NULL, NULL, _t('统计代码'), _t('填写你的各种跟踪统计代码，相当于页尾代码'));
    $form->addInput($GoogleAnalytics);
    
}


/*文章阅读次数统计*/
function get_post_view($archive) {
    $cid = $archive->cid;
    $db = Typecho_Db::get();
    $prefix = $db->getPrefix();
    if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
        $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;');
        echo 0;
        return;
    }
    $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
    if ($archive->is('single')) {
        $views = Typecho_Cookie::get('extend_contents_views');
        if (empty($views)) {
            $views = array();
        } else {
            $views = explode(',', $views);
        }
        if (!in_array($cid, $views)) {
            $db->query($db->update('table.contents')->rows(array('views' => (int)$row['views'] + 1))->where('cid = ?', $cid));
            array_push($views, $cid);
            $views = implode(',', $views);
            Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie
            
        }
    }
    echo $row['views'];
}
